//
//  ChooseCateoryViewCtrl.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/20.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "ChooseCateoryViewCtrl.h"
#import "ChooseCateoryCell.h"
#import "NoteCateoryMode.h"


static NSString *ChooseCateoryIdentifier = @"ChooseCateoryCell";


@interface ChooseCateoryViewCtrl ()

@property (weak, nonatomic) IBOutlet UITableView *mainTableview;

@property (nonatomic,strong)NSMutableArray *cateoryArrs;

@end

@implementation ChooseCateoryViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self defaultConfiguration];
    // Do any additional setup after loading the view from its nib.
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - table设置

- (void)defaultConfiguration {
    self.mainTableview.backgroundColor = kGetColor(250, 250, 250);
    [self.mainTableview registerNib:[UINib nibWithNibName:ChooseCateoryIdentifier bundle:nil] forCellReuseIdentifier:ChooseCateoryIdentifier];
    self.mainTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableView Delegate & Datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cateoryArrs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger rowIndex = indexPath.row;
    NSInteger sectionIndex = indexPath.section;
    
    NoteCateoryMode  *mode = [self.cateoryArrs objectAtIndex:rowIndex];
    ChooseCateoryCell  *cell = [tableView dequeueReusableCellWithIdentifier:ChooseCateoryIdentifier forIndexPath:indexPath];
    
    [cell cellWillDisplay:mode];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger sectionIndex = indexPath.section;
    NSInteger rowIndex = indexPath.row;
    return 44;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger rowIndex = indexPath.row;
    NoteCateoryMode  *mode = [self.cateoryArrs objectAtIndex:rowIndex];
   
    if (self.chsDoneBlock) {
        self.chsDoneBlock(mode);
    }
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - getter
- (NSMutableArray *)cateoryArrs {
    return [[UserConfigManager shareInstance] cateoryArrs];
}

@end
